<template>
  <div style="min-width:1366px;">
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>
        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>

            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" v-model="queryInfo.srm" clearable @clear="clearEvent"></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="tableData"
          border
          height="550"
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          :cell-style="{'text-align':'center'}"
          size="medium"
          stripe
          style="width: 100%;font-size:12px"
        >
          <el-table-column prop="SSDM" label="医院手术编码"></el-table-column>

          <el-table-column prop="SSMC" label="医院手术名称"></el-table-column>

          <el-table-column label="手术分类名称">
            <template slot-scope="scope">
              <el-button type="text" @click="OperationClass()">{{scope.row.SSFLMC}}</el-button>
            </template>
          </el-table-column>

          <el-table-column label="预防使用抗菌药" width="120px">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click="SetPrevent(scope.row.id)"
              >{{(scope.row.anti_define==1)?"有":"——"}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="ypwf" label="手术药品维护"></el-table-column>
          <el-table-column prop="compName" label="操作人/操作时间">
            <template slot-scope="scope">{{scope.row.matchUser}}/{{getDate(scope.row.matchTime)}}</template>
          </el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>
    <!-- 手术分类 -->
    <el-dialog
      title="手术分类"
      :visible.sync="OperationVisible"
      class="editDialog"
      width="30%"
      :before-close="handleClose"
    >
      <div style="width:100%;height:495px">
        <div class="addInput">
          <el-input v-model="addClass" size="small" placeholder="请输入内容"></el-input>
          <el-button style="margin-right:8px" type="primary" size="small" @click="SaveEditSort()">添加</el-button>
        </div>
        <el-table
          :data="this.OperationflData"
          stripe
          border
          height="400"
          style="width: 100%;font-size: 10px"
          :header-cell-style="{'text-align':'center'}"
          :row-style="{height:'40px'}"
          :cell-style="{'text-align':'center',padding:'0px'}"
        >
          <el-table-column prop="id" width="80" label="编码"></el-table-column>
          <el-table-column prop="ssflmc" label="手术分类名称"></el-table-column>
          <el-table-column label="是否在用">
            <template slot-scope="scope">
              <!-- {{scope.row.sfsy}} -->
              <el-select
                v-model="scope.row.sfsy"
                @change="changefl(scope.row.id, $event)"
                size="mini"
              >
                <el-option
                  v-for="item in Poeraoptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table>
        <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->

        <span slot="footer" class="dialog-footer">
          <div class="SortFoot">
            <el-button
              style="margin-right:8px"
              type="primary"
              size="small"
              @click="SaveEditSort()"
            >保存条目排序</el-button>
            <el-button style="margin-right:8px" @click="OperationVisible = false" size="small">取消</el-button>
          </div>
        </span>
      </div>
    </el-dialog>

    <!-- 设置预防使用抗菌药物 -->
    <el-dialog
      title="设置预防使用抗菌药物"
      :visible.sync="preventVisible"
      class="editDialog"
      width="38%"
      :before-close="handleClose"
    >
      <div style="width:100%;height:527px">
        <div class="addInput">
          <el-input v-model="addClass" size="small" placeholder="请输入内容"></el-input>
          <el-button style="margin-right:8px" type="primary" size="small" @click="SaveEditSort()">搜索</el-button>
        </div>
        <el-table
          :data="this.PreventData.PreventList"
          stripe
          border
          height="400"
          style="width: 100%;font-size: 10px"
          :header-cell-style="{'text-align':'center'}"
          :row-style="{height:'40px'}"
          :cell-style="{'text-align':'center',padding:'0px'}"
        >
          <el-table-column type="index" width="80"></el-table-column>
          <el-table-column prop="ssflmc" width="70" label="操作"></el-table-column>
          <el-table-column prop="drugName" label="抗菌药物名称"></el-table-column>
          <el-table-column prop="add_user" width="100" label="操作人"></el-table-column>
        </el-table>
        <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->
        <el-pagination
          @size-change="handleSizeChange2"
          @current-change="handleCurrentChange2"
          :current-page.sync="PreventData.page"
          :page-sizes="[20, 50]"
          :page-size="20"
          background
          layout=" total,sizes, prev, pager, next"
          :total="PreventData.total"
        ></el-pagination>
        <span slot="footer" class="dialog-footer">
          <div class="SortFoot">
            <el-button
              style="margin-right:8px"
              type="primary"
              size="small"
              @click="SaveEditSort()"
            >保存条目排序</el-button>
            <el-button style="margin-right:8px" @click="OperationVisible = false" size="small">取消</el-button>
          </div>
        </span>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getOperationDictList,
  getdate,
  getOperationClass,
  EditOperationInfo,
  getPreventList
} from "@/api/rad";
export default {
  data() {
    return {
      queryInfo: {
        srm: "",
        page: 1,
        pageSize: 20
      },
      total: 0,
      tableData: [],
      OperationVisible: false,
      OperationflData: [],
      Poeraoptions: [
        {
          value: -1,
          label: "不确定"
        },
        {
          value: 0,
          label: "否"
        },
        {
          value: 1,
          label: "是"
        }
      ],
      addClass: "",
      preventVisible: false,
      PreventData: {
        id: "",
        keyword: "",
        page: 1,
        rows: 20,
        total: 0,
        PreventList: []
      }
    };
  },
  created: function() {
    this.getOperationDictList();
  },
  methods: {
    handleClose(done) {
      done();
    },
    getDate(date) {
      return this.$rad.getdate(date);
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getOperationDictList();
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pageList = newPage;
      this.getOperationDictList();
    },
    handleSizeChange2(newSize) {
      this.PreventData.rows = newSize;
      this.getPreventList();
    },
    handleCurrentChange2(newPage) {
      this.PreventData.page = newPage;
      this.getPreventList();
    },
    async getOperationDictList() {
      let res = await this.$rad.getOperationDictList({
        srm: this.queryInfo.srm,
        page: this.queryInfo.page,
        pageSize: this.queryInfo.pageSize
      });
      (this.tableData = res.rows), (this.total = res.total);
      console.log(res.rows);
    },
    getSearchList() {},
    clearEvent() {},
    OperationClass() {
      this.OperationVisible = true;
      this.getOperationClass();
    },
    async getOperationClass() {
      let res = await this.$rad.getOperationClass();
      console.log(res);
      this.OperationflData = res;
    },
    async changefl(id, e) {
      console.log(id);
      console.log(e);
      let res = await this.$rad.EditOperationInfo({
        id: id,
        sfsy: e
      });
      console.log(res);
      if (res.code == 1) {
        return this.$message({
          type: "success",
          message: res.msg
        });
      } else {
        return this.$message({
          type: "error",
          message: res.msg
        });
      }
    },
    // 设置预防用药
    SetPrevent(id) {
      this.preventVisible = true;
      this.PreventData.id = id;
      this.getPreventList();
    },
    async getPreventList() {
      let res = await this.$rad.getPreventList({
        id: this.PreventData.id,
        keyword: this.PreventData.keyword,
        page: this.PreventData.page,
        rows: this.PreventData.rows
      });
      console.log(res);
      this.PreventData.total = res.total;
      this.PreventData.PreventList = res.rows;
    }
  }
};
</script>
<style scoped>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
.editDialog >>> .el-dialog__header {
  margin-bottom: 0px;
}
.editDialog >>> .el-dialog__body {
  padding-left: 0px;
  padding-right: 0px;
}
.SortFoot {
  height: 50px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.addInput {
  height: 45px;
  display: flex;
  align-items: center;
}
.addInput >>> .el-input {
  width: 40%;
  margin-left: 8px;
}
.addInput >>> .el-button {
  margin-left: 8px;
}
</style>